package com.yanfan.ba.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.ba.domain.NjBaDeviceData;
import com.yanfan.ba.service.INjBaDeviceDataService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 楼控设备数据Controller
 *
 * @author genluo
 * @date 2024-11-06
 */
@Api(tags = "楼控设备数据")
@RestController
@RequestMapping("/ba/baData")
public class NjBaDeviceDataController extends BaseController {
    @Autowired
    private INjBaDeviceDataService njBaDeviceDataService;

    /**
     * 查询楼控设备数据列表
     */
    @ApiOperation("楼控设备数据分页列表")
    @PreAuthorize("@ss.hasPermi('ba:baData:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjBaDeviceData njBaDeviceData) {
        startPage();
        List<NjBaDeviceData> list = njBaDeviceDataService.queryPageList(njBaDeviceData);
        return getDataTable(list);
    }

    /**
     * 导出楼控设备数据列表
     */
    @ApiOperation("导出楼控设备数据列表")
    @PreAuthorize("@ss.hasPermi('ba:baData:export')")
    @Log(title = "楼控设备数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjBaDeviceData njBaDeviceData) {
        List<NjBaDeviceData> list = njBaDeviceDataService.queryPageList(njBaDeviceData);
        ExcelUtil<NjBaDeviceData> util = new ExcelUtil<NjBaDeviceData>(NjBaDeviceData.class);
        util.exportExcel(response, list, "楼控设备数据数据");
    }

    /**
     * 获取楼控设备数据详细信息
     */
    @ApiOperation("获取楼控设备数据详细信息")
    @PreAuthorize("@ss.hasPermi('ba:baData:query')")
    @GetMapping(value = "/{instanceNumber}")
    public AjaxResult getInfo(@PathVariable("instanceNumber") Long instanceNumber) {
        return success(njBaDeviceDataService.getById(instanceNumber));
    }

    /**
     * 新增楼控设备数据
     */
    @ApiOperation("新增楼控设备数据")
    @PreAuthorize("@ss.hasPermi('ba:baData:add')")
    @Log(title = "楼控设备数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjBaDeviceData njBaDeviceData) {
        return toAjax(njBaDeviceDataService.save(njBaDeviceData));
    }

    /**
     * 修改楼控设备数据
     */
    @ApiOperation("修改楼控设备数据")
    @PreAuthorize("@ss.hasPermi('ba:baData:edit')")
    @Log(title = "楼控设备数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjBaDeviceData njBaDeviceData) {
        return toAjax(njBaDeviceDataService.updateById(njBaDeviceData));
    }

    /**
     * 删除楼控设备数据
     */
    @ApiOperation("删除楼控设备数据")
    @PreAuthorize("@ss.hasPermi('ba:baData:remove')")
    @Log(title = "楼控设备数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{instanceNumbers}")
    public AjaxResult remove(@PathVariable Long[] instanceNumbers) {
        return toAjax(njBaDeviceDataService.removeBatchByIds(Arrays.asList(instanceNumbers)));
    }
}
